/******************************************************************************
 *                       B O M B E R M A N  2 0 1 2
 * 
 * File Name: Explosion.java
 * 
 * COP 4331 Summer 2012 Project
 * 
 * Authors: Trevor Mancuso, Chris Chiarella, Zach Hoyler, Daniel Martin
 * 
 * 
 * Description: Creates the explosions
 * 
 ******************************************************************************/
package bomberman;

import java.awt.Toolkit;
import java.util.Timer;

public class Explosion extends Entity {

    int time;
    Bomberman game;
    Timer timer = new Timer();
    //Constructor: set the position and sprite and timeout timer.
    Explosion(int x,int y, Bomberman game)
    {
        this.xPos = x;
        this.yPos = y;
        time = 2;
        this.game = game;
        timer.schedule(new BombCountdown(this),0,500); 
        addToArray();
        setSprite(Bomberman.Sprites.EXPLOSION.getSprite());
    }
    //When the time hits 0, stop displaying the explosion
    public void countDown()
    {
        time--;
        if (time == 0)
        {
            this.destroy();
        }
    }
    private void addToArray()
    {
        if(xPos >= 0 && xPos <= 29 && yPos >= 0 && yPos <= 29)
            game.theGame.explosionArray[xPos][yPos] = this;
    }
    //Destroy the explosion
    public void destroy()
    {
        timer.cancel();
        if(xPos >= 0 && xPos <= 29 && yPos >= 0 && yPos <= 29)
            game.theGame.explosionArray[xPos][yPos] = null;
    }
}
